﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Longbow.Data;
using Gammar.Price.ObjectModel;

namespace Gammar.Price.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Sp_Category : ReaderCommand<Sp_CategoryEntity>
    {
        private Guid? _typeId;

        /// <summary>
        /// 
        /// </summary>            
        public Sp_Category(Guid? typeId)
        {
            _typeId = typeId;
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override CommandType CommandType
        {
            get { return CommandType.StoredProcedure; }
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override string CommandText
        {
            get { return "sp_Category"; }
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override void AddParameters(DbParameterCollection parameters, DBAccess db)
        {
            parameters.Add(db.CreateParameter("@typeId", DBAccess.ToDBValue(_typeId), ParameterDirection.Input));
        }

        /// <summary>
        /// 
        /// </summary>            
        protected override Sp_CategoryEntity ParseRow(DbDataReader reader)
        {
            Sp_CategoryEntity obj = new Sp_CategoryEntity();
            obj.Cat_id = (Guid?)DBAccess.ToObjectValue(reader["Cat_id"]);
            obj.Cat_Name = (string)DBAccess.ToObjectValue(reader["Cat_Name"]);
            obj.ItemCount = (int?)DBAccess.ToObjectValue(reader["ItemCount"]);
            obj.CClass_ID = (Guid?)DBAccess.ToObjectValue(reader["CClass_ID"]);
            obj.Cat_Order = (int?)DBAccess.ToObjectValue(reader["Cat_Order"]);
            obj.CClass_Name = (string)DBAccess.ToObjectValue(reader["CClass_Name"]);
            return obj;
        }
    }
}